#if DYNAMIC_PROPERTY_TEST
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.Drawing.Design;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace CaveArt.UIcomp
{
	[TypeConverter(typeof(PropertyCommandConverter))]
	public class PropertyCommand
	{
		private bool _ReadOnly=false;
		private bool _Visible=true;
		private string _Name="Property Command";

		[Category("Property Name")]
		public string Name
		{
			get{return _Name;}
		}

		[Category("Visibility")]
		public bool ReadOnly
		{
			get{return _ReadOnly;}
			set{_ReadOnly= value;}
		}

		[Category("Visibility")]
		public bool Visible
		{
			get{return _Visible;}
			set{_Visible=value;}
		}

		public PropertyCommand()
		{}

		public PropertyCommand(string Name)
		{
			this._Name= Name;	
		}

		public PropertyCommand(string Name,bool Visible, bool ReadOnly)
		{
			this._Name= Name;
			this._Visible=Visible;
			this._ReadOnly=ReadOnly;
		}

		public override string ToString()
		{
			return Name;
		}
	}

	public class PropertyCommandCollection : CollectionBase
	{
		private CommandComparer _ComComp;

		public CommandComparer ComComp
		{
			get
			{
				if(_ComComp==null)
				{
					_ComComp= new CommandComparer();
				}
				return _ComComp;
			}
		}

		public int Add(PropertyCommand pc)
		{
			return this.InnerList.Add(pc);
		}

		public void AddRange(PropertyCommand[] pcs)
		{
			InnerList.AddRange(pcs);
		}

		public void Remove(PropertyCommand pc)
		{
			InnerList.Remove(pc);
		}

		public new void RemoveAt(int index)
		{
			InnerList.RemoveAt(index);
		}

		public void Sort()
		{
			InnerList.Sort(ComComp);
		}

		public bool Contains(PropertyCommand pc)
		{
			return InnerList.Contains(pc);
		}

		public bool Contains(string Name)
		{
			return this[Name]!=null;
		}

		public PropertyCommand this[string Name]
		{
			get
			{
				InnerList.Sort(ComComp);
				int index= InnerList.BinarySearch(Name,ComComp);
				if(index>-1){return (PropertyCommand)this.InnerList[index]; }
				else{return null;}
			}
		}

		public int BinarySearch(PropertyCommand value)
		{
			InnerList.Sort(ComComp);
			return InnerList.BinarySearch(value,ComComp);
		}

		public PropertyCommand this[int index]
		{
			get{return (PropertyCommand)this.InnerList[index];}
			set{this.InnerList[index]= value;}
		}
	}

	internal class PropertyCommandConverter : ExpandableObjectConverter
	{
		public override bool CanConvertTo(ITypeDescriptorContext context, Type destType) 
		{
			if (destType == typeof(InstanceDescriptor)) 
			{
				return true;
			}
			return base.CanConvertTo(context, destType);
		}	
		
		public override object  ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo info,object value,Type destType )
		{
			if (destType == typeof(InstanceDescriptor)) 
			{
				return new InstanceDescriptor(typeof(PropertyCommand).GetConstructor(new Type[]{typeof(string), typeof(bool), typeof(bool)}), new object[]{((PropertyCommand)value).Name,((PropertyCommand)value).Visible,((PropertyCommand)value).ReadOnly},true);
			}
			return base.ConvertTo(context,info,value,destType);
		}
	}

	
	public class CommandComparer : System.Collections.IComparer
	{
		int System.Collections.IComparer.Compare (object o1, object o2)
		{
			return string.Compare(o1.ToString(),o2.ToString(),true);
		}
	}

	#region NOT NEEDED
	//	public class CustomCommandsCollectionEditor:CustomCollectionEditor
	//	{
	//		protected override CustomCollectionEditorForm CreateForm()
	//		{
	//			return new CustomCollectionEditorDialog ();
	//		}
	//
	//	}
	#endregion
}
#endif